﻿using System;
using System.Threading.Tasks;
using System.Web.Http;
using Ewk.MachineLearning.Persistance.DataAccess;
using Ewk.MachineLearning.Persistance.Domain;

namespace Clustering.MultidimensionalScaling.Web.UI.Controllers
{
    public class WordController : TextEntityController<Word>
    {
        // POST api/word
        public async Task PostAsync([FromBody] string value)
        {
            await Task.Factory.StartNew(() =>
                {
                    using (var catalog = CatalogFactory.NewCatalog())
                    {
                        var repository = new TextEntityRepository<Word>(catalog);
                        var document = new Word {Content = value};

                        repository.Add(document);
                    }
                });
        }

        // PUT api/word/5
        public async Task PutAsync(Guid id, [FromBody]string value)
        {
            await Task.Factory.StartNew(() =>
                {
                    using (var catalog = CatalogFactory.NewCatalog())
                    {
                        var repository = new TextEntityRepository<Word>(catalog);
                        var entity = repository.GetEntityById(id);

                        entity.Content = value;

                        repository.Update(entity);
                    }
                });
        }
    }
}